package com.example.property.controller;

import com.example.property.pojo.PageResult;
import com.example.property.pojo.ResponsePojo;
import com.example.property.pojo.Room;
import com.example.property.service.RoomService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "房屋相关 API")
public class RoomController {
    @Autowired
    RoomService roomService;

    @ApiOperation(value = "分页查询所有房间信息，可以带关键字查询。",
            notes = "application/json 格式<br/>" +
                    "{current:当前页 default 1 required false,<br>" +
                    "size:每页数据量 default 10 required false,<br>" +
                    "builtArea:建筑面积 required false<br>" +
                    "status:房间状态 required false<br>" +
                    "floorNumber:房间所属楼层数 required false<br>" +
                    "buildingNumber:房间所属建筑号 required false}")
    @PostMapping("/pageOfRoom")
    public ResponsePojo<PageResult<Room>> pageOfRooms(
            @RequestBody Map<String, String> map) {
        map.putIfAbsent("current", "1");
        map.putIfAbsent("size", "10");
        return ResponsePojo.success(roomService.pageOfRoom(map));
    }


    @PutMapping("/updateStatus")
    @ApiOperation(value = "批量修改房间状态", notes = "页面需要勾选多 个房间")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idList", required = true, value = "需修改状态的房间 id 列表", dataTypeClass = List.class, paramType = "query"),
            @ApiImplicitParam(name = "status", required = true, value = "修改后的状态")
    })
    public ResponsePojo<Integer> changeRoomStatus(@RequestParam("idList") List<Integer> idList, Integer status) {
        if (idList.size() > 0) {
            try {
                return
                        ResponsePojo.success(roomService.changeRoomStatus(idList, status));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return ResponsePojo.fail(null, "无数据");
    }
}
